<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminRolePermissionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin_role_permissions', function (Blueprint $table) {
            $table->id();
            $table->enum('role', ['super_admin', 'admin', 'operator']); // 角色
            $table->unsignedBigInteger('permission_id'); // 权限ID
            $table->timestamps();
            
            // 外键和索引
            $table->foreign('permission_id')->references('id')->on('admin_permissions')->onDelete('cascade');
            $table->unique(['role', 'permission_id']);
            $table->index(['role']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_role_permissions');
    }
}